<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>digichef.voting.views</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="digichef-module.html">Package&nbsp;digichef</a> ::
        <a href="digichef.voting-module.html">Package&nbsp;voting</a> ::
        Module&nbsp;views
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="digichef.voting.views-pysrc.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<h1 class="epydoc">Source Code for <a href="digichef.voting.views-module.html">Module digichef.voting.views</a></h1>
<pre class="py-src">
<a name="L1"></a><tt class="py-lineno">  1</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">django</tt><tt class="py-op">.</tt><tt class="py-name">contrib</tt><tt class="py-op">.</tt><tt class="py-name">contenttypes</tt><tt class="py-op">.</tt><tt id="link-0" class="py-name" targets="Module digichef.core.models=digichef.core.models-module.html,Module digichef.profiles.models=digichef.profiles.models-module.html,Module digichef.recipes.models=digichef.recipes.models-module.html,Module digichef.recommender.models=digichef.recommender.models-module.html,Module digichef.registration.models=digichef.registration.models-module.html,Module digichef.tagging.models=digichef.tagging.models-module.html,Module digichef.tagging.tests.models=digichef.tagging.tests.models-module.html,Module digichef.util.models=digichef.util.models-module.html,Module digichef.voting.models=digichef.voting.models-module.html,Module digichef.voting.tests.models=digichef.voting.tests.models-module.html"><a title="digichef.core.models
digichef.profiles.models
digichef.recipes.models
digichef.recommender.models
digichef.registration.models
digichef.tagging.models
digichef.tagging.tests.models
digichef.util.models
digichef.voting.models
digichef.voting.tests.models" class="py-name" href="#" onclick="return doclink('link-0', 'models', 'link-0');">models</a></tt> <tt class="py-keyword">import</tt> <tt class="py-name">ContentType</tt> </tt>
<a name="L2"></a><tt class="py-lineno">  2</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">django</tt><tt class="py-op">.</tt><tt id="link-1" class="py-name" targets="Package digichef.core=digichef.core-module.html"><a title="digichef.core" class="py-name" href="#" onclick="return doclink('link-1', 'core', 'link-1');">core</a></tt><tt class="py-op">.</tt><tt class="py-name">exceptions</tt> <tt class="py-keyword">import</tt> <tt class="py-name">ObjectDoesNotExist</tt> </tt>
<a name="L3"></a><tt class="py-lineno">  3</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">django</tt><tt class="py-op">.</tt><tt class="py-name">http</tt> <tt class="py-keyword">import</tt> <tt class="py-name">Http404</tt><tt class="py-op">,</tt> <tt class="py-name">HttpResponse</tt><tt class="py-op">,</tt> <tt class="py-name">HttpResponseRedirect</tt> </tt>
<a name="L4"></a><tt class="py-lineno">  4</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">django</tt><tt class="py-op">.</tt><tt class="py-name">contrib</tt><tt class="py-op">.</tt><tt class="py-name">auth</tt><tt class="py-op">.</tt><tt id="link-2" class="py-name" targets="Module digichef.core.views=digichef.core.views-module.html,Module digichef.profiles.views=digichef.profiles.views-module.html,Module digichef.recipes.views=digichef.recipes.views-module.html,Module digichef.recommender.views=digichef.recommender.views-module.html,Module digichef.registration.views=digichef.registration.views-module.html,Module digichef.tagging.views=digichef.tagging.views-module.html,Module digichef.util.views=digichef.util.views-module.html,Module digichef.views=digichef.views-module.html,Module digichef.voting.views=digichef.voting.views-module.html"><a title="digichef.core.views
digichef.profiles.views
digichef.recipes.views
digichef.recommender.views
digichef.registration.views
digichef.tagging.views
digichef.util.views
digichef.views
digichef.voting.views" class="py-name" href="#" onclick="return doclink('link-2', 'views', 'link-2');">views</a></tt> <tt class="py-keyword">import</tt> <tt class="py-name">redirect_to_login</tt> </tt>
<a name="L5"></a><tt class="py-lineno">  5</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">django</tt><tt class="py-op">.</tt><tt id="link-3" class="py-name" targets="Function re.template()=re-module.html#template"><a title="re.template" class="py-name" href="#" onclick="return doclink('link-3', 'template', 'link-3');">template</a></tt> <tt class="py-keyword">import</tt> <tt class="py-name">loader</tt><tt class="py-op">,</tt> <tt class="py-name">RequestContext</tt> </tt>
<a name="L6"></a><tt class="py-lineno">  6</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">django</tt><tt class="py-op">.</tt><tt id="link-4" class="py-name" targets="Module digichef.profiles.utils=digichef.profiles.utils-module.html,Module digichef.recommender.utils=digichef.recommender.utils-module.html,Module digichef.tagging.utils=digichef.tagging.utils-module.html"><a title="digichef.profiles.utils
digichef.recommender.utils
digichef.tagging.utils" class="py-name" href="#" onclick="return doclink('link-4', 'utils', 'link-4');">utils</a></tt> <tt class="py-keyword">import</tt> <tt id="link-5" class="py-name" targets="Package digichef.simplejson=digichef.simplejson-module.html"><a title="digichef.simplejson" class="py-name" href="#" onclick="return doclink('link-5', 'simplejson', 'link-5');">simplejson</a></tt> </tt>
<a name="L7"></a><tt class="py-lineno">  7</tt>  <tt class="py-line"> </tt>
<a name="L8"></a><tt class="py-lineno">  8</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-6" class="py-name" targets="Package digichef.voting=digichef.voting-module.html"><a title="digichef.voting" class="py-name" href="#" onclick="return doclink('link-6', 'voting', 'link-6');">voting</a></tt><tt class="py-op">.</tt><tt id="link-7" class="py-name"><a title="digichef.core.models
digichef.profiles.models
digichef.recipes.models
digichef.recommender.models
digichef.registration.models
digichef.tagging.models
digichef.tagging.tests.models
digichef.util.models
digichef.voting.models
digichef.voting.tests.models" class="py-name" href="#" onclick="return doclink('link-7', 'models', 'link-0');">models</a></tt> <tt class="py-keyword">import</tt> <tt id="link-8" class="py-name" targets="Class digichef.voting.models.Vote=digichef.voting.models.Vote-class.html"><a title="digichef.voting.models.Vote" class="py-name" href="#" onclick="return doclink('link-8', 'Vote', 'link-8');">Vote</a></tt> </tt>
<a name="L9"></a><tt class="py-lineno">  9</tt>  <tt class="py-line"> </tt>
<a name="L10"></a><tt class="py-lineno"> 10</tt>  <tt class="py-line"><tt id="link-9" class="py-name" targets="Variable digichef.voting.views.VOTE_DIRECTIONS=digichef.voting.views-module.html#VOTE_DIRECTIONS"><a title="digichef.voting.views.VOTE_DIRECTIONS" class="py-name" href="#" onclick="return doclink('link-9', 'VOTE_DIRECTIONS', 'link-9');">VOTE_DIRECTIONS</a></tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-op">(</tt><tt class="py-string">'up'</tt><tt class="py-op">,</tt> <tt class="py-number">1</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-op">(</tt><tt class="py-string">'down'</tt><tt class="py-op">,</tt> <tt class="py-op">-</tt><tt class="py-number">1</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-op">(</tt><tt class="py-string">'clear'</tt><tt class="py-op">,</tt> <tt class="py-number">0</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L11"></a><tt class="py-lineno"> 11</tt>  <tt class="py-line"> </tt>
<a name="L12"></a><tt class="py-lineno"> 12</tt>  <tt class="py-line"> </tt>
<a name="vote_on_object"></a><div id="vote_on_object-def"><a name="L13"></a><tt class="py-lineno"> 13</tt> <a class="py-toggle" href="#" id="vote_on_object-toggle" onclick="return toggle('vote_on_object');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="digichef.voting.views-module.html#vote_on_object">vote_on_object</a><tt class="py-op">(</tt><tt class="py-param">request</tt><tt class="py-op">,</tt> <tt class="py-param">model</tt><tt class="py-op">,</tt> <tt class="py-param">direction</tt><tt class="py-op">,</tt> <tt class="py-param">post_vote_redirect</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">,</tt> </tt>
<a name="L14"></a><tt class="py-lineno"> 14</tt>  <tt class="py-line">        <tt class="py-param">object_id</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">,</tt> <tt class="py-param">slug</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">,</tt> <tt class="py-param">slug_field</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">,</tt> <tt class="py-param">template_name</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">,</tt> </tt>
<a name="L15"></a><tt class="py-lineno"> 15</tt>  <tt class="py-line">        <tt class="py-param">template_loader</tt><tt class="py-op">=</tt><tt class="py-name">loader</tt><tt class="py-op">,</tt> <tt class="py-param">extra_context</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">,</tt> <tt class="py-param">context_processors</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">,</tt> </tt>
<a name="L16"></a><tt class="py-lineno"> 16</tt>  <tt class="py-line">        <tt class="py-param">template_object_name</tt><tt class="py-op">=</tt><tt class="py-string">'object'</tt><tt class="py-op">,</tt> <tt class="py-param">allow_xmlhttprequest</tt><tt class="py-op">=</tt><tt class="py-name">False</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="vote_on_object-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="vote_on_object-expanded"><a name="L17"></a><tt class="py-lineno"> 17</tt>  <tt class="py-line">    <tt class="py-docstring">"""</tt> </tt>
<a name="L18"></a><tt class="py-lineno"> 18</tt>  <tt class="py-line"><tt class="py-docstring">    Generic object vote function.</tt> </tt>
<a name="L19"></a><tt class="py-lineno"> 19</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L20"></a><tt class="py-lineno"> 20</tt>  <tt class="py-line"><tt class="py-docstring">    The given template will be used to confirm the vote if this view is</tt> </tt>
<a name="L21"></a><tt class="py-lineno"> 21</tt>  <tt class="py-line"><tt class="py-docstring">    fetched using GET; vote registration will only be performed if this</tt> </tt>
<a name="L22"></a><tt class="py-lineno"> 22</tt>  <tt class="py-line"><tt class="py-docstring">    view is POSTed.</tt> </tt>
<a name="L23"></a><tt class="py-lineno"> 23</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L24"></a><tt class="py-lineno"> 24</tt>  <tt class="py-line"><tt class="py-docstring">    If ``allow_xmlhttprequest`` is ``True`` and an XMLHttpRequest is</tt> </tt>
<a name="L25"></a><tt class="py-lineno"> 25</tt>  <tt class="py-line"><tt class="py-docstring">    detected by examining the ``HTTP_X_REQUESTED_WITH`` header, the</tt> </tt>
<a name="L26"></a><tt class="py-lineno"> 26</tt>  <tt class="py-line"><tt class="py-docstring">    ``xmlhttp_vote_on_object`` view will be used to process the</tt> </tt>
<a name="L27"></a><tt class="py-lineno"> 27</tt>  <tt class="py-line"><tt class="py-docstring">    request - this makes it trivial to implement voting via</tt> </tt>
<a name="L28"></a><tt class="py-lineno"> 28</tt>  <tt class="py-line"><tt class="py-docstring">    XMLHttpRequest with a fallback for users who don't have JavaScript</tt> </tt>
<a name="L29"></a><tt class="py-lineno"> 29</tt>  <tt class="py-line"><tt class="py-docstring">    enabled.</tt> </tt>
<a name="L30"></a><tt class="py-lineno"> 30</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L31"></a><tt class="py-lineno"> 31</tt>  <tt class="py-line"><tt class="py-docstring">    Templates:``&lt;app_label&gt;/&lt;model_name&gt;_confirm_vote.html``</tt> </tt>
<a name="L32"></a><tt class="py-lineno"> 32</tt>  <tt class="py-line"><tt class="py-docstring">    Context:</tt> </tt>
<a name="L33"></a><tt class="py-lineno"> 33</tt>  <tt class="py-line"><tt class="py-docstring">        object</tt> </tt>
<a name="L34"></a><tt class="py-lineno"> 34</tt>  <tt class="py-line"><tt class="py-docstring">            The object being voted on.</tt> </tt>
<a name="L35"></a><tt class="py-lineno"> 35</tt>  <tt class="py-line"><tt class="py-docstring">        direction</tt> </tt>
<a name="L36"></a><tt class="py-lineno"> 36</tt>  <tt class="py-line"><tt class="py-docstring">            The type of vote which will be registered for the object.</tt> </tt>
<a name="L37"></a><tt class="py-lineno"> 37</tt>  <tt class="py-line"><tt class="py-docstring">    """</tt> </tt>
<a name="L38"></a><tt class="py-lineno"> 38</tt>  <tt class="py-line">    <tt class="py-keyword">if</tt> <tt class="py-name">allow_xmlhttprequest</tt> <tt class="py-keyword">and</tt> <tt class="py-name">request</tt><tt class="py-op">.</tt><tt class="py-name">is_ajax</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L39"></a><tt class="py-lineno"> 39</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt id="link-10" class="py-name" targets="Function digichef.voting.views.xmlhttprequest_vote_on_object()=digichef.voting.views-module.html#xmlhttprequest_vote_on_object"><a title="digichef.voting.views.xmlhttprequest_vote_on_object" class="py-name" href="#" onclick="return doclink('link-10', 'xmlhttprequest_vote_on_object', 'link-10');">xmlhttprequest_vote_on_object</a></tt><tt class="py-op">(</tt><tt class="py-name">request</tt><tt class="py-op">,</tt> <tt id="link-11" class="py-name" targets="Variable digichef.profiles.forms.ProfileForm.Meta.model=digichef.profiles.forms.ProfileForm.Meta-class.html#model,Variable digichef.tagging.forms.TagAdminForm.Meta.model=digichef.tagging.forms.TagAdminForm.Meta-class.html#model"><a title="digichef.profiles.forms.ProfileForm.Meta.model
digichef.tagging.forms.TagAdminForm.Meta.model" class="py-name" href="#" onclick="return doclink('link-11', 'model', 'link-11');">model</a></tt><tt class="py-op">,</tt> <tt class="py-name">direction</tt><tt class="py-op">,</tt> </tt>
<a name="L40"></a><tt class="py-lineno"> 40</tt>  <tt class="py-line">                                             <tt id="link-12" class="py-name" targets="Variable digichef.tagging.models.TaggedItem.object_id=digichef.tagging.models.TaggedItem-class.html#object_id,Variable digichef.voting.models.Vote.object_id=digichef.voting.models.Vote-class.html#object_id"><a title="digichef.tagging.models.TaggedItem.object_id
digichef.voting.models.Vote.object_id" class="py-name" href="#" onclick="return doclink('link-12', 'object_id', 'link-12');">object_id</a></tt><tt class="py-op">=</tt><tt id="link-13" class="py-name"><a title="digichef.tagging.models.TaggedItem.object_id
digichef.voting.models.Vote.object_id" class="py-name" href="#" onclick="return doclink('link-13', 'object_id', 'link-12');">object_id</a></tt><tt class="py-op">,</tt> <tt class="py-name">slug</tt><tt class="py-op">=</tt><tt class="py-name">slug</tt><tt class="py-op">,</tt> </tt>
<a name="L41"></a><tt class="py-lineno"> 41</tt>  <tt class="py-line">                                             <tt class="py-name">slug_field</tt><tt class="py-op">=</tt><tt class="py-name">slug_field</tt><tt class="py-op">)</tt> </tt>
<a name="L42"></a><tt class="py-lineno"> 42</tt>  <tt class="py-line"> </tt>
<a name="L43"></a><tt class="py-lineno"> 43</tt>  <tt class="py-line">    <tt class="py-keyword">if</tt> <tt class="py-name">extra_context</tt> <tt class="py-keyword">is</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> <tt class="py-name">extra_context</tt> <tt class="py-op">=</tt> <tt class="py-op">{</tt><tt class="py-op">}</tt> </tt>
<a name="L44"></a><tt class="py-lineno"> 44</tt>  <tt class="py-line">    <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt class="py-name">request</tt><tt class="py-op">.</tt><tt id="link-14" class="py-name" targets="Variable digichef.profiles.models.Profile.user=digichef.profiles.models.Profile-class.html#user,Variable digichef.registration.models.RegistrationProfile.user=digichef.registration.models.RegistrationProfile-class.html#user,Variable digichef.util.models.UserMeta.user=digichef.util.models.UserMeta-class.html#user,Variable digichef.voting.models.Vote.user=digichef.voting.models.Vote-class.html#user"><a title="digichef.profiles.models.Profile.user
digichef.registration.models.RegistrationProfile.user
digichef.util.models.UserMeta.user
digichef.voting.models.Vote.user" class="py-name" href="#" onclick="return doclink('link-14', 'user', 'link-14');">user</a></tt><tt class="py-op">.</tt><tt class="py-name">is_authenticated</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L45"></a><tt class="py-lineno"> 45</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-name">redirect_to_login</tt><tt class="py-op">(</tt><tt class="py-name">request</tt><tt class="py-op">.</tt><tt id="link-15" class="py-name" targets="Variable digichef.recommender.utils.path=digichef.recommender.utils-module.html#path"><a title="digichef.recommender.utils.path" class="py-name" href="#" onclick="return doclink('link-15', 'path', 'link-15');">path</a></tt><tt class="py-op">)</tt> </tt>
<a name="L46"></a><tt class="py-lineno"> 46</tt>  <tt class="py-line"> </tt>
<a name="L47"></a><tt class="py-lineno"> 47</tt>  <tt class="py-line">    <tt class="py-keyword">try</tt><tt class="py-op">:</tt> </tt>
<a name="L48"></a><tt class="py-lineno"> 48</tt>  <tt class="py-line">        <tt id="link-16" class="py-name" targets="Variable digichef.voting.models.Vote.vote=digichef.voting.models.Vote-class.html#vote"><a title="digichef.voting.models.Vote.vote" class="py-name" href="#" onclick="return doclink('link-16', 'vote', 'link-16');">vote</a></tt> <tt class="py-op">=</tt> <tt class="py-name">dict</tt><tt class="py-op">(</tt><tt id="link-17" class="py-name"><a title="digichef.voting.views.VOTE_DIRECTIONS" class="py-name" href="#" onclick="return doclink('link-17', 'VOTE_DIRECTIONS', 'link-9');">VOTE_DIRECTIONS</a></tt><tt class="py-op">)</tt><tt class="py-op">[</tt><tt class="py-name">direction</tt><tt class="py-op">]</tt> </tt>
<a name="L49"></a><tt class="py-lineno"> 49</tt>  <tt class="py-line">    <tt class="py-keyword">except</tt> <tt class="py-name">KeyError</tt><tt class="py-op">:</tt> </tt>
<a name="L50"></a><tt class="py-lineno"> 50</tt>  <tt class="py-line">        <tt class="py-keyword">raise</tt> <tt class="py-name">AttributeError</tt><tt class="py-op">(</tt><tt class="py-string">"'%s' is not a valid vote type."</tt> <tt class="py-op">%</tt> <tt class="py-name">vote_type</tt><tt class="py-op">)</tt> </tt>
<a name="L51"></a><tt class="py-lineno"> 51</tt>  <tt class="py-line"> </tt>
<a name="L52"></a><tt class="py-lineno"> 52</tt>  <tt class="py-line">    <tt class="py-comment"># Look up the object to be voted on</tt> </tt>
<a name="L53"></a><tt class="py-lineno"> 53</tt>  <tt class="py-line">    <tt class="py-name">lookup_kwargs</tt> <tt class="py-op">=</tt> <tt class="py-op">{</tt><tt class="py-op">}</tt> </tt>
<a name="L54"></a><tt class="py-lineno"> 54</tt>  <tt class="py-line">    <tt class="py-keyword">if</tt> <tt id="link-18" class="py-name"><a title="digichef.tagging.models.TaggedItem.object_id
digichef.voting.models.Vote.object_id" class="py-name" href="#" onclick="return doclink('link-18', 'object_id', 'link-12');">object_id</a></tt><tt class="py-op">:</tt> </tt>
<a name="L55"></a><tt class="py-lineno"> 55</tt>  <tt class="py-line">        <tt class="py-name">lookup_kwargs</tt><tt class="py-op">[</tt><tt class="py-string">'%s__exact'</tt> <tt class="py-op">%</tt> <tt id="link-19" class="py-name"><a title="digichef.profiles.forms.ProfileForm.Meta.model
digichef.tagging.forms.TagAdminForm.Meta.model" class="py-name" href="#" onclick="return doclink('link-19', 'model', 'link-11');">model</a></tt><tt class="py-op">.</tt><tt class="py-name">_meta</tt><tt class="py-op">.</tt><tt class="py-name">pk</tt><tt class="py-op">.</tt><tt id="link-20" class="py-name" targets="Variable digichef.recommender.models.TestItem.name=digichef.recommender.models.TestItem-class.html#name,Variable digichef.tagging.models.Tag.name=digichef.tagging.models.Tag-class.html#name,Variable digichef.tagging.tests.models.Article.name=digichef.tagging.tests.models.Article-class.html#name,Variable digichef.tagging.tests.models.Link.name=digichef.tagging.tests.models.Link-class.html#name,Variable digichef.voting.tests.models.Item.name=digichef.voting.tests.models.Item-class.html#name"><a title="digichef.recommender.models.TestItem.name
digichef.tagging.models.Tag.name
digichef.tagging.tests.models.Article.name
digichef.tagging.tests.models.Link.name
digichef.voting.tests.models.Item.name" class="py-name" href="#" onclick="return doclink('link-20', 'name', 'link-20');">name</a></tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt id="link-21" class="py-name"><a title="digichef.tagging.models.TaggedItem.object_id
digichef.voting.models.Vote.object_id" class="py-name" href="#" onclick="return doclink('link-21', 'object_id', 'link-12');">object_id</a></tt> </tt>
<a name="L56"></a><tt class="py-lineno"> 56</tt>  <tt class="py-line">    <tt class="py-keyword">elif</tt> <tt class="py-name">slug</tt> <tt class="py-keyword">and</tt> <tt class="py-name">slug_field</tt><tt class="py-op">:</tt> </tt>
<a name="L57"></a><tt class="py-lineno"> 57</tt>  <tt class="py-line">        <tt class="py-name">lookup_kwargs</tt><tt class="py-op">[</tt><tt class="py-string">'%s__exact'</tt> <tt class="py-op">%</tt> <tt class="py-name">slug_field</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">slug</tt> </tt>
<a name="L58"></a><tt class="py-lineno"> 58</tt>  <tt class="py-line">    <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L59"></a><tt class="py-lineno"> 59</tt>  <tt class="py-line">        <tt class="py-keyword">raise</tt> <tt class="py-name">AttributeError</tt><tt class="py-op">(</tt><tt class="py-string">'Generic vote view must be called with either '</tt> </tt>
<a name="L60"></a><tt class="py-lineno"> 60</tt>  <tt class="py-line">                             <tt class="py-string">'object_id or slug and slug_field.'</tt><tt class="py-op">)</tt> </tt>
<a name="L61"></a><tt class="py-lineno"> 61</tt>  <tt class="py-line">    <tt class="py-keyword">try</tt><tt class="py-op">:</tt> </tt>
<a name="L62"></a><tt class="py-lineno"> 62</tt>  <tt class="py-line">        <tt class="py-name">obj</tt> <tt class="py-op">=</tt> <tt id="link-22" class="py-name"><a title="digichef.profiles.forms.ProfileForm.Meta.model
digichef.tagging.forms.TagAdminForm.Meta.model" class="py-name" href="#" onclick="return doclink('link-22', 'model', 'link-11');">model</a></tt><tt class="py-op">.</tt><tt class="py-name">_default_manager</tt><tt class="py-op">.</tt><tt class="py-name">get</tt><tt class="py-op">(</tt><tt class="py-op">**</tt><tt class="py-name">lookup_kwargs</tt><tt class="py-op">)</tt> </tt>
<a name="L63"></a><tt class="py-lineno"> 63</tt>  <tt class="py-line">    <tt class="py-keyword">except</tt> <tt class="py-name">ObjectDoesNotExist</tt><tt class="py-op">:</tt> </tt>
<a name="L64"></a><tt class="py-lineno"> 64</tt>  <tt class="py-line">        <tt class="py-keyword">raise</tt> <tt class="py-name">Http404</tt><tt class="py-op">,</tt> <tt class="py-string">'No %s found for %s.'</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt><tt id="link-23" class="py-name"><a title="digichef.profiles.forms.ProfileForm.Meta.model
digichef.tagging.forms.TagAdminForm.Meta.model" class="py-name" href="#" onclick="return doclink('link-23', 'model', 'link-11');">model</a></tt><tt class="py-op">.</tt><tt class="py-name">_meta</tt><tt class="py-op">.</tt><tt class="py-name">app_label</tt><tt class="py-op">,</tt> <tt class="py-name">lookup_kwargs</tt><tt class="py-op">)</tt> </tt>
<a name="L65"></a><tt class="py-lineno"> 65</tt>  <tt class="py-line"> </tt>
<a name="L66"></a><tt class="py-lineno"> 66</tt>  <tt class="py-line">    <tt class="py-keyword">if</tt> <tt class="py-name">request</tt><tt class="py-op">.</tt><tt class="py-name">method</tt> <tt class="py-op">==</tt> <tt class="py-string">'POST'</tt><tt class="py-op">:</tt> </tt>
<a name="L67"></a><tt class="py-lineno"> 67</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-name">post_vote_redirect</tt> <tt class="py-keyword">is</tt> <tt class="py-keyword">not</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> </tt>
<a name="L68"></a><tt class="py-lineno"> 68</tt>  <tt class="py-line">            <tt class="py-name">next</tt> <tt class="py-op">=</tt> <tt class="py-name">post_vote_redirect</tt> </tt>
<a name="L69"></a><tt class="py-lineno"> 69</tt>  <tt class="py-line">        <tt class="py-keyword">elif</tt> <tt class="py-name">request</tt><tt class="py-op">.</tt><tt class="py-name">REQUEST</tt><tt class="py-op">.</tt><tt class="py-name">has_key</tt><tt class="py-op">(</tt><tt class="py-string">'next'</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L70"></a><tt class="py-lineno"> 70</tt>  <tt class="py-line">            <tt class="py-name">next</tt> <tt class="py-op">=</tt> <tt class="py-name">request</tt><tt class="py-op">.</tt><tt class="py-name">REQUEST</tt><tt class="py-op">[</tt><tt class="py-string">'next'</tt><tt class="py-op">]</tt> </tt>
<a name="L71"></a><tt class="py-lineno"> 71</tt>  <tt class="py-line">        <tt class="py-keyword">elif</tt> <tt class="py-name">hasattr</tt><tt class="py-op">(</tt><tt class="py-name">obj</tt><tt class="py-op">,</tt> <tt class="py-string">'get_absolute_url'</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L72"></a><tt class="py-lineno"> 72</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt> <tt class="py-name">callable</tt><tt class="py-op">(</tt><tt class="py-name">getattr</tt><tt class="py-op">(</tt><tt class="py-name">obj</tt><tt class="py-op">,</tt> <tt class="py-string">'get_absolute_url'</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L73"></a><tt class="py-lineno"> 73</tt>  <tt class="py-line">                <tt class="py-name">next</tt> <tt class="py-op">=</tt> <tt class="py-name">obj</tt><tt class="py-op">.</tt><tt id="link-24" class="py-name" targets="Method digichef.profiles.models.Profile.get_absolute_url()=digichef.profiles.models.Profile-class.html#get_absolute_url,Method digichef.recipes.models.Recipe.get_absolute_url()=digichef.recipes.models.Recipe-class.html#get_absolute_url"><a title="digichef.profiles.models.Profile.get_absolute_url
digichef.recipes.models.Recipe.get_absolute_url" class="py-name" href="#" onclick="return doclink('link-24', 'get_absolute_url', 'link-24');">get_absolute_url</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L74"></a><tt class="py-lineno"> 74</tt>  <tt class="py-line">            <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L75"></a><tt class="py-lineno"> 75</tt>  <tt class="py-line">                <tt class="py-name">next</tt> <tt class="py-op">=</tt> <tt class="py-name">obj</tt><tt class="py-op">.</tt><tt id="link-25" class="py-name"><a title="digichef.profiles.models.Profile.get_absolute_url
digichef.recipes.models.Recipe.get_absolute_url" class="py-name" href="#" onclick="return doclink('link-25', 'get_absolute_url', 'link-24');">get_absolute_url</a></tt> </tt>
<a name="L76"></a><tt class="py-lineno"> 76</tt>  <tt class="py-line">        <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L77"></a><tt class="py-lineno"> 77</tt>  <tt class="py-line">            <tt class="py-keyword">raise</tt> <tt class="py-name">AttributeError</tt><tt class="py-op">(</tt><tt class="py-string">'Generic vote view must be called with either '</tt> </tt>
<a name="L78"></a><tt class="py-lineno"> 78</tt>  <tt class="py-line">                                 <tt class="py-string">'post_vote_redirect, a "next" parameter in '</tt> </tt>
<a name="L79"></a><tt class="py-lineno"> 79</tt>  <tt class="py-line">                                 <tt class="py-string">'the request, or the object being voted on '</tt> </tt>
<a name="L80"></a><tt class="py-lineno"> 80</tt>  <tt class="py-line">                                 <tt class="py-string">'must define a get_absolute_url method or '</tt> </tt>
<a name="L81"></a><tt class="py-lineno"> 81</tt>  <tt class="py-line">                                 <tt class="py-string">'property.'</tt><tt class="py-op">)</tt> </tt>
<a name="L82"></a><tt class="py-lineno"> 82</tt>  <tt class="py-line">        <tt id="link-26" class="py-name"><a title="digichef.voting.models.Vote" class="py-name" href="#" onclick="return doclink('link-26', 'Vote', 'link-8');">Vote</a></tt><tt class="py-op">.</tt><tt id="link-27" class="py-name" targets="Variable digichef.recommender.models.Recommender.objects=digichef.recommender.models.Recommender-class.html#objects,Variable digichef.registration.models.RegistrationProfile.objects=digichef.registration.models.RegistrationProfile-class.html#objects,Variable digichef.tagging.models.Tag.objects=digichef.tagging.models.Tag-class.html#objects,Variable digichef.tagging.models.TaggedItem.objects=digichef.tagging.models.TaggedItem-class.html#objects,Variable digichef.voting.models.Vote.objects=digichef.voting.models.Vote-class.html#objects"><a title="digichef.recommender.models.Recommender.objects
digichef.registration.models.RegistrationProfile.objects
digichef.tagging.models.Tag.objects
digichef.tagging.models.TaggedItem.objects
digichef.voting.models.Vote.objects" class="py-name" href="#" onclick="return doclink('link-27', 'objects', 'link-27');">objects</a></tt><tt class="py-op">.</tt><tt class="py-name">record_vote</tt><tt class="py-op">(</tt><tt class="py-name">obj</tt><tt class="py-op">,</tt> <tt class="py-name">request</tt><tt class="py-op">.</tt><tt id="link-28" class="py-name"><a title="digichef.profiles.models.Profile.user
digichef.registration.models.RegistrationProfile.user
digichef.util.models.UserMeta.user
digichef.voting.models.Vote.user" class="py-name" href="#" onclick="return doclink('link-28', 'user', 'link-14');">user</a></tt><tt class="py-op">,</tt> <tt id="link-29" class="py-name"><a title="digichef.voting.models.Vote.vote" class="py-name" href="#" onclick="return doclink('link-29', 'vote', 'link-16');">vote</a></tt><tt class="py-op">)</tt> </tt>
<a name="L83"></a><tt class="py-lineno"> 83</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-name">HttpResponseRedirect</tt><tt class="py-op">(</tt><tt class="py-name">next</tt><tt class="py-op">)</tt> </tt>
<a name="L84"></a><tt class="py-lineno"> 84</tt>  <tt class="py-line">    <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L85"></a><tt class="py-lineno"> 85</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt class="py-name">template_name</tt><tt class="py-op">:</tt> </tt>
<a name="L86"></a><tt class="py-lineno"> 86</tt>  <tt class="py-line">            <tt class="py-name">template_name</tt> <tt class="py-op">=</tt> <tt class="py-string">'%s/%s_confirm_vote.html'</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt> </tt>
<a name="L87"></a><tt class="py-lineno"> 87</tt>  <tt class="py-line">                <tt id="link-30" class="py-name"><a title="digichef.profiles.forms.ProfileForm.Meta.model
digichef.tagging.forms.TagAdminForm.Meta.model" class="py-name" href="#" onclick="return doclink('link-30', 'model', 'link-11');">model</a></tt><tt class="py-op">.</tt><tt class="py-name">_meta</tt><tt class="py-op">.</tt><tt class="py-name">app_label</tt><tt class="py-op">,</tt> <tt id="link-31" class="py-name"><a title="digichef.profiles.forms.ProfileForm.Meta.model
digichef.tagging.forms.TagAdminForm.Meta.model" class="py-name" href="#" onclick="return doclink('link-31', 'model', 'link-11');">model</a></tt><tt class="py-op">.</tt><tt class="py-name">_meta</tt><tt class="py-op">.</tt><tt class="py-name">object_name</tt><tt class="py-op">.</tt><tt class="py-name">lower</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L88"></a><tt class="py-lineno"> 88</tt>  <tt class="py-line">        <tt class="py-name">t</tt> <tt class="py-op">=</tt> <tt class="py-name">template_loader</tt><tt class="py-op">.</tt><tt class="py-name">get_template</tt><tt class="py-op">(</tt><tt class="py-name">template_name</tt><tt class="py-op">)</tt> </tt>
<a name="L89"></a><tt class="py-lineno"> 89</tt>  <tt class="py-line">        <tt class="py-name">c</tt> <tt class="py-op">=</tt> <tt class="py-name">RequestContext</tt><tt class="py-op">(</tt><tt class="py-name">request</tt><tt class="py-op">,</tt> <tt class="py-op">{</tt> </tt>
<a name="L90"></a><tt class="py-lineno"> 90</tt>  <tt class="py-line">            <tt class="py-name">template_object_name</tt><tt class="py-op">:</tt> <tt class="py-name">obj</tt><tt class="py-op">,</tt> </tt>
<a name="L91"></a><tt class="py-lineno"> 91</tt>  <tt class="py-line">            <tt class="py-string">'direction'</tt><tt class="py-op">:</tt> <tt class="py-name">direction</tt><tt class="py-op">,</tt> </tt>
<a name="L92"></a><tt class="py-lineno"> 92</tt>  <tt class="py-line">        <tt class="py-op">}</tt><tt class="py-op">,</tt> <tt class="py-name">context_processors</tt><tt class="py-op">)</tt> </tt>
<a name="L93"></a><tt class="py-lineno"> 93</tt>  <tt class="py-line">        <tt class="py-keyword">for</tt> <tt class="py-name">key</tt><tt class="py-op">,</tt> <tt class="py-name">value</tt> <tt class="py-keyword">in</tt> <tt class="py-name">extra_context</tt><tt class="py-op">.</tt><tt class="py-name">items</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L94"></a><tt class="py-lineno"> 94</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt> <tt class="py-name">callable</tt><tt class="py-op">(</tt><tt class="py-name">value</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L95"></a><tt class="py-lineno"> 95</tt>  <tt class="py-line">                <tt class="py-name">c</tt><tt class="py-op">[</tt><tt class="py-name">key</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">value</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L96"></a><tt class="py-lineno"> 96</tt>  <tt class="py-line">            <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L97"></a><tt class="py-lineno"> 97</tt>  <tt class="py-line">                <tt class="py-name">c</tt><tt class="py-op">[</tt><tt class="py-name">key</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">value</tt> </tt>
<a name="L98"></a><tt class="py-lineno"> 98</tt>  <tt class="py-line">        <tt class="py-name">response</tt> <tt class="py-op">=</tt> <tt class="py-name">HttpResponse</tt><tt class="py-op">(</tt><tt class="py-name">t</tt><tt class="py-op">.</tt><tt id="link-32" class="py-name" targets="Method digichef.tagging.templatetags.tagging_tags.TagCloudForModelNode.render()=digichef.tagging.templatetags.tagging_tags.TagCloudForModelNode-class.html#render,Method digichef.tagging.templatetags.tagging_tags.TaggedObjectsNode.render()=digichef.tagging.templatetags.tagging_tags.TaggedObjectsNode-class.html#render,Method digichef.tagging.templatetags.tagging_tags.TagsForModelNode.render()=digichef.tagging.templatetags.tagging_tags.TagsForModelNode-class.html#render,Method digichef.tagging.templatetags.tagging_tags.TagsForObjectNode.render()=digichef.tagging.templatetags.tagging_tags.TagsForObjectNode-class.html#render,Method digichef.voting.templatetags.voting_tags.DictEntryForItemNode.render()=digichef.voting.templatetags.voting_tags.DictEntryForItemNode-class.html#render,Method digichef.voting.templatetags.voting_tags.ScoreForObjectNode.render()=digichef.voting.templatetags.voting_tags.ScoreForObjectNode-class.html#render,Method digichef.voting.templatetags.voting_tags.ScoresForObjectsNode.render()=digichef.voting.templatetags.voting_tags.ScoresForObjectsNode-class.html#render,Method digichef.voting.templatetags.voting_tags.VoteByUserNode.render()=digichef.voting.templatetags.voting_tags.VoteByUserNode-class.html#render,Method digichef.voting.templatetags.voting_tags.VotesByUserNode.render()=digichef.voting.templatetags.voting_tags.VotesByUserNode-class.html#render"><a title="digichef.tagging.templatetags.tagging_tags.TagCloudForModelNode.render
digichef.tagging.templatetags.tagging_tags.TaggedObjectsNode.render
digichef.tagging.templatetags.tagging_tags.TagsForModelNode.render
digichef.tagging.templatetags.tagging_tags.TagsForObjectNode.render
digichef.voting.templatetags.voting_tags.DictEntryForItemNode.render
digichef.voting.templatetags.voting_tags.ScoreForObjectNode.render
digichef.voting.templatetags.voting_tags.ScoresForObjectsNode.render
digichef.voting.templatetags.voting_tags.VoteByUserNode.render
digichef.voting.templatetags.voting_tags.VotesByUserNode.render" class="py-name" href="#" onclick="return doclink('link-32', 'render', 'link-32');">render</a></tt><tt class="py-op">(</tt><tt class="py-name">c</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L99"></a><tt class="py-lineno"> 99</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-name">response</tt> </tt>
</div><a name="L100"></a><tt class="py-lineno">100</tt>  <tt class="py-line"> </tt>
<a name="json_error_response"></a><div id="json_error_response-def"><a name="L101"></a><tt class="py-lineno">101</tt> <a class="py-toggle" href="#" id="json_error_response-toggle" onclick="return toggle('json_error_response');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="digichef.voting.views-module.html#json_error_response">json_error_response</a><tt class="py-op">(</tt><tt class="py-param">error_message</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="json_error_response-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="json_error_response-expanded"><a name="L102"></a><tt class="py-lineno">102</tt>  <tt class="py-line">    <tt class="py-keyword">return</tt> <tt class="py-name">HttpResponse</tt><tt class="py-op">(</tt><tt id="link-33" class="py-name"><a title="digichef.simplejson" class="py-name" href="#" onclick="return doclink('link-33', 'simplejson', 'link-5');">simplejson</a></tt><tt class="py-op">.</tt><tt id="link-34" class="py-name" targets="Function digichef.simplejson.dumps()=digichef.simplejson-module.html#dumps"><a title="digichef.simplejson.dumps" class="py-name" href="#" onclick="return doclink('link-34', 'dumps', 'link-34');">dumps</a></tt><tt class="py-op">(</tt><tt class="py-name">dict</tt><tt class="py-op">(</tt><tt class="py-name">success</tt><tt class="py-op">=</tt><tt class="py-name">False</tt><tt class="py-op">,</tt> </tt>
<a name="L103"></a><tt class="py-lineno">103</tt>  <tt class="py-line">                                              <tt class="py-name">error_message</tt><tt class="py-op">=</tt><tt class="py-name">error_message</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
</div><a name="L104"></a><tt class="py-lineno">104</tt>  <tt class="py-line"> </tt>
<a name="xmlhttprequest_vote_on_object"></a><div id="xmlhttprequest_vote_on_object-def"><a name="L105"></a><tt class="py-lineno">105</tt> <a class="py-toggle" href="#" id="xmlhttprequest_vote_on_object-toggle" onclick="return toggle('xmlhttprequest_vote_on_object');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="digichef.voting.views-module.html#xmlhttprequest_vote_on_object">xmlhttprequest_vote_on_object</a><tt class="py-op">(</tt><tt class="py-param">request</tt><tt class="py-op">,</tt> <tt class="py-param">model</tt><tt class="py-op">,</tt> <tt class="py-param">direction</tt><tt class="py-op">,</tt> </tt>
<a name="L106"></a><tt class="py-lineno">106</tt>  <tt class="py-line">    <tt class="py-param">object_id</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">,</tt> <tt class="py-param">slug</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">,</tt> <tt class="py-param">slug_field</tt><tt class="py-op">=</tt><tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="xmlhttprequest_vote_on_object-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="xmlhttprequest_vote_on_object-expanded"><a name="L107"></a><tt class="py-lineno">107</tt>  <tt class="py-line">    <tt class="py-docstring">"""</tt> </tt>
<a name="L108"></a><tt class="py-lineno">108</tt>  <tt class="py-line"><tt class="py-docstring">    Generic object vote function for use via XMLHttpRequest.</tt> </tt>
<a name="L109"></a><tt class="py-lineno">109</tt>  <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L110"></a><tt class="py-lineno">110</tt>  <tt class="py-line"><tt class="py-docstring">    Properties of the resulting JSON object:</tt> </tt>
<a name="L111"></a><tt class="py-lineno">111</tt>  <tt class="py-line"><tt class="py-docstring">        success</tt> </tt>
<a name="L112"></a><tt class="py-lineno">112</tt>  <tt class="py-line"><tt class="py-docstring">            ``true`` if the vote was successfully processed, ``false``</tt> </tt>
<a name="L113"></a><tt class="py-lineno">113</tt>  <tt class="py-line"><tt class="py-docstring">            otherwise.</tt> </tt>
<a name="L114"></a><tt class="py-lineno">114</tt>  <tt class="py-line"><tt class="py-docstring">        score</tt> </tt>
<a name="L115"></a><tt class="py-lineno">115</tt>  <tt class="py-line"><tt class="py-docstring">            The object's updated score and number of votes if the vote</tt> </tt>
<a name="L116"></a><tt class="py-lineno">116</tt>  <tt class="py-line"><tt class="py-docstring">            was successfully processed.</tt> </tt>
<a name="L117"></a><tt class="py-lineno">117</tt>  <tt class="py-line"><tt class="py-docstring">        error_message</tt> </tt>
<a name="L118"></a><tt class="py-lineno">118</tt>  <tt class="py-line"><tt class="py-docstring">            Contains an error message if the vote was not successfully</tt> </tt>
<a name="L119"></a><tt class="py-lineno">119</tt>  <tt class="py-line"><tt class="py-docstring">            processed.</tt> </tt>
<a name="L120"></a><tt class="py-lineno">120</tt>  <tt class="py-line"><tt class="py-docstring">    """</tt> </tt>
<a name="L121"></a><tt class="py-lineno">121</tt>  <tt class="py-line">    <tt class="py-keyword">if</tt> <tt class="py-name">request</tt><tt class="py-op">.</tt><tt class="py-name">method</tt> <tt class="py-op">==</tt> <tt class="py-string">'GET'</tt><tt class="py-op">:</tt> </tt>
<a name="L122"></a><tt class="py-lineno">122</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt id="link-35" class="py-name" targets="Function digichef.voting.views.json_error_response()=digichef.voting.views-module.html#json_error_response"><a title="digichef.voting.views.json_error_response" class="py-name" href="#" onclick="return doclink('link-35', 'json_error_response', 'link-35');">json_error_response</a></tt><tt class="py-op">(</tt> </tt>
<a name="L123"></a><tt class="py-lineno">123</tt>  <tt class="py-line">            <tt class="py-string">'XMLHttpRequest votes can only be made using POST.'</tt><tt class="py-op">)</tt> </tt>
<a name="L124"></a><tt class="py-lineno">124</tt>  <tt class="py-line">    <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt class="py-name">request</tt><tt class="py-op">.</tt><tt id="link-36" class="py-name"><a title="digichef.profiles.models.Profile.user
digichef.registration.models.RegistrationProfile.user
digichef.util.models.UserMeta.user
digichef.voting.models.Vote.user" class="py-name" href="#" onclick="return doclink('link-36', 'user', 'link-14');">user</a></tt><tt class="py-op">.</tt><tt class="py-name">is_authenticated</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L125"></a><tt class="py-lineno">125</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt id="link-37" class="py-name"><a title="digichef.voting.views.json_error_response" class="py-name" href="#" onclick="return doclink('link-37', 'json_error_response', 'link-35');">json_error_response</a></tt><tt class="py-op">(</tt><tt class="py-string">'Not authenticated.'</tt><tt class="py-op">)</tt> </tt>
<a name="L126"></a><tt class="py-lineno">126</tt>  <tt class="py-line"> </tt>
<a name="L127"></a><tt class="py-lineno">127</tt>  <tt class="py-line">    <tt class="py-keyword">try</tt><tt class="py-op">:</tt> </tt>
<a name="L128"></a><tt class="py-lineno">128</tt>  <tt class="py-line">        <tt id="link-38" class="py-name"><a title="digichef.voting.models.Vote.vote" class="py-name" href="#" onclick="return doclink('link-38', 'vote', 'link-16');">vote</a></tt> <tt class="py-op">=</tt> <tt class="py-name">dict</tt><tt class="py-op">(</tt><tt id="link-39" class="py-name"><a title="digichef.voting.views.VOTE_DIRECTIONS" class="py-name" href="#" onclick="return doclink('link-39', 'VOTE_DIRECTIONS', 'link-9');">VOTE_DIRECTIONS</a></tt><tt class="py-op">)</tt><tt class="py-op">[</tt><tt class="py-name">direction</tt><tt class="py-op">]</tt> </tt>
<a name="L129"></a><tt class="py-lineno">129</tt>  <tt class="py-line">    <tt class="py-keyword">except</tt> <tt class="py-name">KeyError</tt><tt class="py-op">:</tt> </tt>
<a name="L130"></a><tt class="py-lineno">130</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt id="link-40" class="py-name"><a title="digichef.voting.views.json_error_response" class="py-name" href="#" onclick="return doclink('link-40', 'json_error_response', 'link-35');">json_error_response</a></tt><tt class="py-op">(</tt> </tt>
<a name="L131"></a><tt class="py-lineno">131</tt>  <tt class="py-line">            <tt class="py-string">'\'%s\' is not a valid vote type.'</tt> <tt class="py-op">%</tt> <tt class="py-name">direction</tt><tt class="py-op">)</tt> </tt>
<a name="L132"></a><tt class="py-lineno">132</tt>  <tt class="py-line"> </tt>
<a name="L133"></a><tt class="py-lineno">133</tt>  <tt class="py-line">    <tt class="py-comment"># Look up the object to be voted on</tt> </tt>
<a name="L134"></a><tt class="py-lineno">134</tt>  <tt class="py-line">    <tt class="py-name">lookup_kwargs</tt> <tt class="py-op">=</tt> <tt class="py-op">{</tt><tt class="py-op">}</tt> </tt>
<a name="L135"></a><tt class="py-lineno">135</tt>  <tt class="py-line">    <tt class="py-keyword">if</tt> <tt id="link-41" class="py-name"><a title="digichef.tagging.models.TaggedItem.object_id
digichef.voting.models.Vote.object_id" class="py-name" href="#" onclick="return doclink('link-41', 'object_id', 'link-12');">object_id</a></tt><tt class="py-op">:</tt> </tt>
<a name="L136"></a><tt class="py-lineno">136</tt>  <tt class="py-line">        <tt class="py-name">lookup_kwargs</tt><tt class="py-op">[</tt><tt class="py-string">'%s__exact'</tt> <tt class="py-op">%</tt> <tt id="link-42" class="py-name"><a title="digichef.profiles.forms.ProfileForm.Meta.model
digichef.tagging.forms.TagAdminForm.Meta.model" class="py-name" href="#" onclick="return doclink('link-42', 'model', 'link-11');">model</a></tt><tt class="py-op">.</tt><tt class="py-name">_meta</tt><tt class="py-op">.</tt><tt class="py-name">pk</tt><tt class="py-op">.</tt><tt id="link-43" class="py-name"><a title="digichef.recommender.models.TestItem.name
digichef.tagging.models.Tag.name
digichef.tagging.tests.models.Article.name
digichef.tagging.tests.models.Link.name
digichef.voting.tests.models.Item.name" class="py-name" href="#" onclick="return doclink('link-43', 'name', 'link-20');">name</a></tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt id="link-44" class="py-name"><a title="digichef.tagging.models.TaggedItem.object_id
digichef.voting.models.Vote.object_id" class="py-name" href="#" onclick="return doclink('link-44', 'object_id', 'link-12');">object_id</a></tt> </tt>
<a name="L137"></a><tt class="py-lineno">137</tt>  <tt class="py-line">    <tt class="py-keyword">elif</tt> <tt class="py-name">slug</tt> <tt class="py-keyword">and</tt> <tt class="py-name">slug_field</tt><tt class="py-op">:</tt> </tt>
<a name="L138"></a><tt class="py-lineno">138</tt>  <tt class="py-line">        <tt class="py-name">lookup_kwargs</tt><tt class="py-op">[</tt><tt class="py-string">'%s__exact'</tt> <tt class="py-op">%</tt> <tt class="py-name">slug_field</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">slug</tt> </tt>
<a name="L139"></a><tt class="py-lineno">139</tt>  <tt class="py-line">    <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L140"></a><tt class="py-lineno">140</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt id="link-45" class="py-name"><a title="digichef.voting.views.json_error_response" class="py-name" href="#" onclick="return doclink('link-45', 'json_error_response', 'link-35');">json_error_response</a></tt><tt class="py-op">(</tt><tt class="py-string">'Generic XMLHttpRequest vote view must be '</tt> </tt>
<a name="L141"></a><tt class="py-lineno">141</tt>  <tt class="py-line">                                   <tt class="py-string">'called with either object_id or slug and '</tt> </tt>
<a name="L142"></a><tt class="py-lineno">142</tt>  <tt class="py-line">                                   <tt class="py-string">'slug_field.'</tt><tt class="py-op">)</tt> </tt>
<a name="L143"></a><tt class="py-lineno">143</tt>  <tt class="py-line">    <tt class="py-keyword">try</tt><tt class="py-op">:</tt> </tt>
<a name="L144"></a><tt class="py-lineno">144</tt>  <tt class="py-line">        <tt class="py-name">obj</tt> <tt class="py-op">=</tt> <tt id="link-46" class="py-name"><a title="digichef.profiles.forms.ProfileForm.Meta.model
digichef.tagging.forms.TagAdminForm.Meta.model" class="py-name" href="#" onclick="return doclink('link-46', 'model', 'link-11');">model</a></tt><tt class="py-op">.</tt><tt class="py-name">_default_manager</tt><tt class="py-op">.</tt><tt class="py-name">get</tt><tt class="py-op">(</tt><tt class="py-op">**</tt><tt class="py-name">lookup_kwargs</tt><tt class="py-op">)</tt> </tt>
<a name="L145"></a><tt class="py-lineno">145</tt>  <tt class="py-line">    <tt class="py-keyword">except</tt> <tt class="py-name">ObjectDoesNotExist</tt><tt class="py-op">:</tt> </tt>
<a name="L146"></a><tt class="py-lineno">146</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt id="link-47" class="py-name"><a title="digichef.voting.views.json_error_response" class="py-name" href="#" onclick="return doclink('link-47', 'json_error_response', 'link-35');">json_error_response</a></tt><tt class="py-op">(</tt> </tt>
<a name="L147"></a><tt class="py-lineno">147</tt>  <tt class="py-line">            <tt class="py-string">'No %s found for %s.'</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt><tt id="link-48" class="py-name"><a title="digichef.profiles.forms.ProfileForm.Meta.model
digichef.tagging.forms.TagAdminForm.Meta.model" class="py-name" href="#" onclick="return doclink('link-48', 'model', 'link-11');">model</a></tt><tt class="py-op">.</tt><tt class="py-name">_meta</tt><tt class="py-op">.</tt><tt id="link-49" class="py-name" targets="Variable digichef.registration.models.RegistrationProfile.Meta.verbose_name=digichef.registration.models.RegistrationProfile.Meta-class.html#verbose_name,Variable digichef.tagging.models.Tag.Meta.verbose_name=digichef.tagging.models.Tag.Meta-class.html#verbose_name,Variable digichef.tagging.models.TaggedItem.Meta.verbose_name=digichef.tagging.models.TaggedItem.Meta-class.html#verbose_name"><a title="digichef.registration.models.RegistrationProfile.Meta.verbose_name
digichef.tagging.models.Tag.Meta.verbose_name
digichef.tagging.models.TaggedItem.Meta.verbose_name" class="py-name" href="#" onclick="return doclink('link-49', 'verbose_name', 'link-49');">verbose_name</a></tt><tt class="py-op">,</tt> <tt class="py-name">lookup_kwargs</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L148"></a><tt class="py-lineno">148</tt>  <tt class="py-line"> </tt>
<a name="L149"></a><tt class="py-lineno">149</tt>  <tt class="py-line">    <tt class="py-comment"># Vote and respond</tt> </tt>
<a name="L150"></a><tt class="py-lineno">150</tt>  <tt class="py-line">    <tt id="link-50" class="py-name"><a title="digichef.voting.models.Vote" class="py-name" href="#" onclick="return doclink('link-50', 'Vote', 'link-8');">Vote</a></tt><tt class="py-op">.</tt><tt id="link-51" class="py-name"><a title="digichef.recommender.models.Recommender.objects
digichef.registration.models.RegistrationProfile.objects
digichef.tagging.models.Tag.objects
digichef.tagging.models.TaggedItem.objects
digichef.voting.models.Vote.objects" class="py-name" href="#" onclick="return doclink('link-51', 'objects', 'link-27');">objects</a></tt><tt class="py-op">.</tt><tt class="py-name">record_vote</tt><tt class="py-op">(</tt><tt class="py-name">obj</tt><tt class="py-op">,</tt> <tt class="py-name">request</tt><tt class="py-op">.</tt><tt id="link-52" class="py-name"><a title="digichef.profiles.models.Profile.user
digichef.registration.models.RegistrationProfile.user
digichef.util.models.UserMeta.user
digichef.voting.models.Vote.user" class="py-name" href="#" onclick="return doclink('link-52', 'user', 'link-14');">user</a></tt><tt class="py-op">,</tt> <tt id="link-53" class="py-name"><a title="digichef.voting.models.Vote.vote" class="py-name" href="#" onclick="return doclink('link-53', 'vote', 'link-16');">vote</a></tt><tt class="py-op">)</tt> </tt>
<a name="L151"></a><tt class="py-lineno">151</tt>  <tt class="py-line">    <tt class="py-keyword">return</tt> <tt class="py-name">HttpResponse</tt><tt class="py-op">(</tt><tt id="link-54" class="py-name"><a title="digichef.simplejson" class="py-name" href="#" onclick="return doclink('link-54', 'simplejson', 'link-5');">simplejson</a></tt><tt class="py-op">.</tt><tt id="link-55" class="py-name"><a title="digichef.simplejson.dumps" class="py-name" href="#" onclick="return doclink('link-55', 'dumps', 'link-34');">dumps</a></tt><tt class="py-op">(</tt><tt class="py-op">{</tt> </tt>
<a name="L152"></a><tt class="py-lineno">152</tt>  <tt class="py-line">        <tt class="py-string">'success'</tt><tt class="py-op">:</tt> <tt class="py-name">True</tt><tt class="py-op">,</tt> </tt>
<a name="L153"></a><tt class="py-lineno">153</tt>  <tt class="py-line">        <tt class="py-string">'score'</tt><tt class="py-op">:</tt> <tt id="link-56" class="py-name"><a title="digichef.voting.models.Vote" class="py-name" href="#" onclick="return doclink('link-56', 'Vote', 'link-8');">Vote</a></tt><tt class="py-op">.</tt><tt id="link-57" class="py-name"><a title="digichef.recommender.models.Recommender.objects
digichef.registration.models.RegistrationProfile.objects
digichef.tagging.models.Tag.objects
digichef.tagging.models.TaggedItem.objects
digichef.voting.models.Vote.objects" class="py-name" href="#" onclick="return doclink('link-57', 'objects', 'link-27');">objects</a></tt><tt class="py-op">.</tt><tt id="link-58" class="py-name" targets="Method digichef.voting.managers.VoteManager.get_score()=digichef.voting.managers.VoteManager-class.html#get_score"><a title="digichef.voting.managers.VoteManager.get_score" class="py-name" href="#" onclick="return doclink('link-58', 'get_score', 'link-58');">get_score</a></tt><tt class="py-op">(</tt><tt class="py-name">obj</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> </tt>
<a name="L154"></a><tt class="py-lineno">154</tt>  <tt class="py-line">    <tt class="py-op">}</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
</div><a name="L155"></a><tt class="py-lineno">155</tt>  <tt class="py-line"> </tt><script type="text/javascript">
<!--
expandto(location.href);
// -->
</script>
</pre>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Thu Apr  1 02:28:31 2010
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
